package com.skywolf.chem.pageconfig.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skywolf.chem.article.entity.Article;
import com.skywolf.chem.article.service.IArticleService;
import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.pageconfig.pojo.param.FirstPagePC;
import com.skywolf.chem.pageconfig.service.IFirstPageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * PC首页内容表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-06-22
 */
@RestController
@RequestMapping("/ct/pageconfig/first-page")
public class FirstPageController {

    @Autowired
    IFirstPageService firstPageService;

    @Autowired
    IArticleService articleService;


    @ApiOperation(value = "获取PC首页内容",notes = "获取PC首页内容")
    @RequestMapping(value = "/getPCFirstPageConfig",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<FirstPagePC> getPCFirstPageConfig() {
        FirstPagePC config = firstPageService.getPCFirstPageConfig();
        return RespData.success(config);
    }

    @ApiOperation(value = "内容搜索接口-搜索帖子",notes = "内容搜索接口-搜索帖子")
    @RequestMapping(value = "/search",method = {RequestMethod.GET,RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<Article> search(@RequestParam(value = "",required = true) String content) {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        String sql="limit 0,20";
        queryWrapper.select("title", "id", "sub_title", "cover_url","art_type","created_time","updated_time").eq("art_status",3).like("title", content).last(sql);
        List<Article> article = articleService.list(queryWrapper);
        return RespData.success(article);
    }
}
